﻿@model List<CMP.ERP.Model.ExpressMatch>
@{
    Layout = null;
}
@Html.Action("Account_Show", "Account");

<div class="content">
    <div class="right" id="mainFrame">
        <div class="header">
            <div class="header-right">
                <form method="post" action="/Express_mate/AddMateCompany">
                    <div id="modal-container-973559" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:400px; margin-left:-150px;">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h3 id="myModalLabel">
                                快递匹配系统
                            </h3>
                        </div>
                        <div class="modal-body">

                            <table class="table table-hover table-bordered " style="width:400px;text-align:center;margin:0 auto;border:2px solid #428bca;">
                                <tbody>
                                    <tr>
                                        <th>公司名称</th>
                                        <td>
                                            <select id="Select1">
                                                <option value="">--请选择--</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>匹配地址</th>
                                        <td>
                                            <div id="div1"></div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>

                        <div class="modal-footer">
                            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button> <button type="button" onclick="Add()" class="btn btn-default"><span class="icon-inbox"></span>保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- 顶部 -->
        <div id="middle">
            <div class="Switch"></div>
            <script type="text/javascript">
                $(document).ready(function (e) {
                    $(".Switch").click(function () {
                        $(".left").toggle();

                    });
                });
            </script>
            <div class="right" id="mainFrame">
                <div class="right_cont">
                    <ul class="breadcrumb">
                        当前位置：
                        <a href="/Home/Index">首页</a>
                        <span class="divider">/</span>
                        快递匹配
                    </ul>
                    <div class="title_right"><strong>快递快速匹配</strong></div>
                    <div style="width:100%; margin:auto">
                        <div>
                            <form method="get" action="/Express_mate/SelMateCompany">
                                <table>
                                    <tr>
                                        @*<td>
                                            @Html.DropDownList("Express_Company_Id", "--请选择--")
                                            <button type="submit" class="btn btn-default">
                                                <span class="icon-search">
                                                </span>查询
                                            </button>
                                        </td>*@
                                        <td>
                                            <button id="modal-973559" href="#modal-container-973559" role="button" type="button" class="btn btn-default" data-toggle="modal">
                                                <span class="icon-plus"></span>新增
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        <div style="margin-top:20px;">
                            <table class="table  table-hover table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>公司编码</th>
                                        <th>公司名称</th>
                                        <th>省/市</th>
                                        <th>市/区</th>
                                    </tr>
                                </thead>
                                <tbody id="tbody1"></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //下拉框
        $.ajax({
            type: "post",
            url: "/Express_mate/ShowExpressCompany",
            success: function (data) {
                $(data).each(function (index, item) {
                    var str = '<option value="' + item.Express_Company_Id + '">' + item.Express_Company_Name + '</option>';
                    $("#Select1").append(str);
                });
            }
        });
        //显示快递匹配信息
        $.ajax({
            type: "post",
            url: "/Express_mate/ShowExpressCompany",
            success: function (data) {
                $(data).each(function (index, item) {
                    var ss = '<tr><td>' + item.Express_Company_Id + '</td><td>' + item.Express_Company_Name + '</td><td><span id="aa' + item.Express_Company_Id + '"></span></td><td><span id="bb' + item.Express_Company_Id + '"></span></td></tr>';
                    $("#tbody1").append(ss);
                    var Poid = item.Express_Company_Id;
                    //根据快递公司编码查询匹配地址(省/市)
                    $.ajax({
                        type: "post",
                        url: "/Express_mate/ShowMatch",
                        data: {
                            id: Poid
                        },
                        cache: false,
                        success: function (data) {
                            var cit = "";
                            $(data).each(function (index, item) {
                                cit += item.P_Name + ',';
                            });
                            cit = cit.substr(0, cit.length - 1);
                            $("#aa" + Poid + "").html(cit);
                        }
                    });
                    //根据快递公司编码查询匹配地址(市/区)
                    $.ajax({
                        type: "post",
                        url: "/Express_mate/GetExpressMatchShow",
                        data: {
                            id: Poid
                        },
                        cache: false,
                        success: function (data) {
                            var cit = "";
                            $(data).each(function (index, item) {
                                cit += item.P_Name + ',';
                            });
                            cit = cit.substr(0, cit.length - 1);
                            $("#bb" + Poid + "").html(cit);
                        }
                    });
                });
            }
        });
        //显示省市区
        $.ajax({
            type: "post",
            url: "/Express_mate/ShowProvince1",
            asyn: false,
            data: {
                P_City: 0
            },
            success: function (d) {
                $(d).each(function (index, item) {
                    var apen = '<span id="s' + item.P_Id + '"><input type="checkbox" value="' + item.P_Id + '" id="ss' + item.P_Id + '" onclick="fun(' + item.P_Id + ')"/>' + item.P_Name + '<br/></span><br/>';
                    $("#div1").append(apen);
                    var Poid = item.P_Id;
                    $.ajax({
                        type: "post",
                        url: "/Express_mate/ShowProvince1",
                        asyn: false,
                        data: {
                            P_City: Poid
                        },
                        success: function (data) {
                            $(data).each(function (index, item) {
                                var str = '<input type="checkbox" value="' + item.P_Id + '" name="ck' + Poid + '" onclick="fun1(' + Poid + ')"/>' + item.P_Name + '';
                                $("#s" + Poid + "").append(str);
                            });
                            var ss = "<br/>";
                            $("#s" + Poid + "").append(ss);
                        }
                    });
                });
            }
        });
        //根据快递公司下拉框显示省市区
        $("#Select1").change(function () {
            $("input:checkbox").attr("checked", false);
            var i = $("#Select1").val();
            $.ajax({
                type: "post",
                url: "/Express_mate/GetExpressMatch1",
                data: {
                    id: i
                },
                success: function (data) {
                    $(data).each(function (index, item) {
                        $("input:checkbox").each(function () {
                            if ($(this).val() == item.P_Id) {
                                $(this).attr("checked", true);
                            }
                        });
                    });
                }
            });
        });
    });
    //全选
    function fun(id) {
        var cklist = $("[name=ck" + id + "]");
        var str = $("#ss" + id + "").attr("checked");
        if (str == "checked") {
            $(cklist).attr("checked", "checked");
        }
        else {
            $(cklist).removeAttr("checked");
        }

    }
    //反选
    //function fun1(id) {
    //    var cklist1 = $("#ss" + id + "");
    //    var str1 = $("[name=ck" + id + "]").attr("checked");
    //    if (str1 == "checked") {
    //        $(cklist1).attr("checked", "checked");
    //    }
    //    else {
    //        $(cklist1).removeAttr("checked");
    //    }
    //}
    //添加(删除)匹配信息
    function Add() {
        var as = $("#Select1").val();;
        var p = "";
        $(":checked").each(function (data, item) {
            if ($(this).attr("checked") == "checked") {
                p += $(this).val() + ",";
            }
        });
        p = p.substr(0, p.length - 1);
        $.ajax({
            type: "post",
            url: "/Express_mate/AddMateCompany",
            data: {
                Express_Company_Id: as,
                P_Id: p
            },
            success: function (data) {
                if (data > 0) {
                    alert("添加成功!");
                    location.reload();
                }
            }
        });
    }
</script>

